home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP2.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.2 KB  |  44 lines

  1. rem 
  2. rem $Header: examp2.sql 7020100.1 94/09/28 16:39:53 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp2.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     gclossma   12/02/92 -  cuz 
  15. Rem     rvasired   05/12/92 -  Creation 
  16. /*
  17. ** This block debits account 3 by $500 only if there are sufficient
  18. ** funds to cover the withdrawal.
  19. **
  20. ** Copyright (c) 1989,1992 by Oracle Corporation
  21. */
  22.  
  23. DECLARE
  24.     acct_balance  NUMBER(11,2);
  25.     acct          CONSTANT NUMBER(4) := 3;
  26.     debit_amt     CONSTANT NUMBER(5,2) := 500.00;
  27. BEGIN
  28.     SELECT bal INTO acct_balance FROM accounts
  29.         WHERE account_id = acct
  30.         FOR UPDATE OF bal;
  31.     
  32.     IF acct_balance >= debit_amt THEN
  33.         UPDATE accounts SET bal = bal - debit_amt
  34.             WHERE account_id = acct;
  35.     ELSE
  36.         INSERT INTO temp VALUES
  37.             (acct, acct_balance, 'Insufficient funds');
  38.                 -- insert account, current balance, and message
  39.     END IF;
  40.  
  41.     COMMIT;
  42. END;
  43. /
  44.